package com.lq.educationsystem.common.util;


import com.lq.educationsystem.common.constant.ResultContant;

public class ResultBuild {

    public ResultBuild() {
    }

    //定义成功状态
    public static Result buildOk(){
        Result result = new Result();
        result.setMessage(ResultContant.SUCCESS_RESULT.getMessage());
        result.setCode(ResultContant.SUCCESS_RESULT.getCode());

        return result;
    }
    //定义成功状态
    public static <T> Result<T> buildOk(T data){
        Result result = new Result();
        result.setMessage(ResultContant.SUCCESS_RESULT.getMessage());
        result.setCode(ResultContant.SUCCESS_RESULT.getCode());
        result.setData(data);
        return result;
    }

    //定义成功状态包含数据
    public static <T> Result buildOk(Result<T> result,T data){

        result.setMessage(ResultContant.SUCCESS_RESULT.getMessage());
        result.setCode(ResultContant.SUCCESS_RESULT.getCode());
        result.setData(data);
        return result;
    }
    //定义失败状态
    public static Result buildDefeat(){
        Result result = new Result();
        result.setMessage(ResultContant.DEFEAT_RESULT.getMessage());
        result.setCode(ResultContant.DEFEAT_RESULT.getCode());

        return result;
    }
    //定义失败状态可以传递参数
    public static<T> Result<T> buildDefeat(Result<T> result,T data){
        result.setMessage(ResultContant.DEFEAT_RESULT.getMessage());
        result.setCode(ResultContant.DEFEAT_RESULT.getCode());
        result.setData(data);
        return result;
    }
    //定义异常状态
    public static Result buildError(){
        Result result = new Result();
        result.setMessage(ResultContant.ERROR_RESULT.getMessage());
        result.setCode(ResultContant.ERROR_RESULT.getCode());

        return result;
    }

}
